package karileet.meeting.profile.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Model object for complex data exchange between user preferences and app
 * <p/>
 * Created by markus on 31.10.14.
 */
public class ThirdParty {
    public static String FACEBOOK = "com.facebook.katana";
    public static String FACEBOOKMESS = "com.facebook.orca";
    public static String WHATSAPP = "com.whatsapp";
    public static String SNAPCHAT = "com.snapchat.android";
    public static String SKYPE = "com.skype.raider";
    public static String LINKEDIN = "com.linkedin.android";
    public static String HANGOUTS = "com.google.android.talk";
    public static String GMAIL = "com.google.android.gm";
    public static String EXCHANGE = "com.android.email";
    public static String CALENDAR = "com.android.calendar";

    private HashMap<String, Boolean> apps = new HashMap<String, Boolean>();

    public ThirdParty() {
        apps.put(FACEBOOK, false);
        apps.put(FACEBOOKMESS, false);
        apps.put(WHATSAPP, false);
        apps.put(SNAPCHAT, false);
        apps.put(SKYPE, false);
        apps.put(LINKEDIN, false);
        apps.put(HANGOUTS, false);
        apps.put(GMAIL, false);
        apps.put(EXCHANGE, false);
        apps.put(CALENDAR, false);
    }

    public HashMap<String, Boolean> getApps() {
        return this.apps;
    }

    public void setAppEnabled(String app) {
        apps.put(app, true);
    }

    public void set(String app, Boolean state) {
        apps.put(app, state);
    }

    public void stringToThirdParty(String string) {
        String[] apps = string.split(",");
        for (String app : apps) {
            if (!app.equals("")) {
                setAppEnabled(app);
            }
        }
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (java.util.Map.Entry<String, Boolean> set : apps.entrySet()) {
            if (set.getValue()) {
                sb.append(set.getKey()).append(",");
            }
        }
        return sb.toString();
    }

    public List<String> toStringArray() {
        List<String> listOfString = new ArrayList<String>();

        for (java.util.Map.Entry<String, Boolean> set : apps.entrySet()) {
            if (set.getValue()) {
                listOfString.add(set.getKey());
            }
        }
        return listOfString;
    }
}
